package com.lq.file.filemanager.entity;

import lombok.Data;

import java.util.HashMap;

/**
 * @program: file-manager
 * @description: 返回实体类
 * @author: LQ
 * @create: 2021-08-07 11:13
 */
@Data
public class ResponseBase extends HashMap {
    public static final Integer SUCCESS_CODE = 0;
    public static final Integer ERROR_CODE = -1;

    private Integer code = SUCCESS_CODE;
    private String message = "";
    private Object result = "";

    public static ResponseBase ok() {
        return ok("");
    }

    public static ResponseBase fail() {
        return new ResponseBase().setCode(ERROR_CODE);
    }

    public static ResponseBase fail(String message) {
        return new ResponseBase().setCode(ERROR_CODE).setMessage(message);
    }

    public static ResponseBase ok(Object result) {
        return new ResponseBase().setCode(SUCCESS_CODE).setResult(result);
    }

    public static ResponseBase ok(String message) {
        return new ResponseBase().setCode(SUCCESS_CODE).setMessage(message);
    }

    public static ResponseBase ok(String message, Object result) {
        return new ResponseBase().setCode(SUCCESS_CODE).setMessage(message).setResult(result);
    }

    public ResponseBase setCode(Integer code) {
        this.code = code;
        this.put("code", code);
        return this;
    }

    public ResponseBase setMessage(String message) {
        this.message = message;
        this.put("message", message);
        return this;
    }

    public ResponseBase setResult(Object result) {
        this.result = result;
        this.put("result", result);
        return this;
    }
}
